package com.ddx.service.impl;

import com.ddx.common.util.DataUtil;
import com.ddx.common.util.FastDFSClient;
import com.ddx.controller.core.ShoppingController;
import com.ddx.dao.ShoppingCommentMapper;
import com.ddx.dao.ShoppingStoreMapper;
import com.ddx.pojo.ShoppingComment;
import com.ddx.pojo.ShoppingStore;
import com.ddx.service.IShoppingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.io.*;

/**
 * @author dudianbo
 * @ClassName: ${CLASSNAME}
 * @Description: ${DESCRIPTION}
 * @date 2019/2/17
 */
@Service
public class ShoppingServiceImpl implements IShoppingService {
    private static final Logger logger = LoggerFactory.getLogger(ShoppingServiceImpl.class);
    @Autowired
    ShoppingCommentMapper shoppingCommentMapper;
    @Autowired
    ShoppingStoreMapper shoppingStoreMapper;
    @Override
    public void addComment(ShoppingComment shoppingComment) {
        logger.info("添加商品评价入参shoppingComment={}",shoppingComment);
        shoppingCommentMapper.insertSelective(shoppingComment);
    }

    @Override
    public void uploadAvatar(String base64Avatar,String userId) throws Exception{
        logger.info("修改店铺头像入参userId={}",userId);
        String[] s=base64Avatar.split(",");
        if(s.length>1){
            byte[] b= DataUtil.GenerateImage(s[1]);
            String url= FastDFSClient.uploadFileByByteAndGroup(b,"group1");
            ShoppingStore record=new ShoppingStore();
            record.setUserId(userId);
            record.setPicture(url);
            shoppingStoreMapper.updatePictureByUserId(record);

        }
    }

//        public static void main(String[] args)
//        {
//            String strImg = GetImageStr();
//            System.out.println(strImg);
//            GenerateImage(strImg);
//        }
//

}
